<?php
session_start();
if (!isset($_SESSION['admin']))
    header('location:index.php');
if (!isset($_REQUEST['confirm']))
    header('location:manufacturer_information.php');
?>

<!DOCTYPE HTML>
<html>

    <head>
        <title>3D|Didongday 3D- Di động đây</title>
        <?php include('modules/page_head.php'); ?>
    </head>

    <body>
        <div id="main">
            <div id="header">
                <div id="logo">
                    <h1><a href="mainpage.html">Didongde</a></h1>
                    <div class="slogan">Where you can find your own best suitable mobile</div>
                    <?php include('modules/logo_header.php'); ?>
                </div>
                <div id="menubar">
                    <?php include('modules/menubar.php'); ?>
                </div>
            </div>
            <div id="site_content">
                <div id="sidebar_container">
                    <h2>Tìm kiếm nhanh</h2>
                    <div class="sidebar">
                        <?php
                        include ("modules/quick_search.php");
                        show_manu();
                        ?>
                    </div>
                    <div class="sidebar">
                        <?php show_price(); ?>
                    </div>
                </div>
                <div id="content">
                    <!-- insert the page content here -->
                    <?php
                    if (isset($_REQUEST['confirm'])) {
                        $manuid = $_COOKIE['manuid'];
                        $name = $_POST['name'];
                        $email = $_POST['email'];
                        $address = $_POST['addr'];
                        $phonenum = $_POST['phone'];
                    }

                    //Connect to database, in this case, connect to localhost
                    include_once('conf/dbconfig.php');
                    $cfg = new dbconfig();
                    $host = $cfg->get_dbhost();
                    $db = $cfg->get_dbname();
                    $usr = $cfg->get_dbusername();
                    $pass = $cfg->get_dbpwd();
                    $connection = pg_connect("host = $host dbname = $db user = $usr password = $pass")
                            or die("Cannot connect to database server: " . pg_last_error());

                    //xem trong database có bao nhiêu tài khoản manufacturer
                    $query = "update manufacturer set name = '$name', email = '$email', address = '$address', phone_number = '$phonenum' where manuid = '$manuid'";
                    $check = pg_query($connection, $query);
                    if (pg_affected_rows($check))
                        echo "Sửa đổi thành công <br/>Click vào <a href = \"manufacturer_information.php\">đây</a> để quay về trang trước."
                        ?>

                </div>
            </div>
            <div id="footer">
                <?php include('modules/footer.php'); ?>
            </div>
        </div>
    </body>
</html>
